package com.qna;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
 
public class DummyDB {
    private List<String> relatedProduct;
    private List<String> relatedToTopicList;
    
    public DummyDB() {

    	String productData = "Site Accelerator,Cloud Monitor,Universal HD";

    	relatedProduct = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(productData, ",");
        
        //Parse the country CSV list and set as Array
        while(st.hasMoreTokens()) {
        	relatedProduct.add(st.nextToken().trim());
        }

        String strTags = "Site Accelerator,Streaming,Download receipts";
        relatedToTopicList = new ArrayList<String>();
        StringTokenizer st2 = new StringTokenizer(strTags, ",");
        
        //Parse the tags CSV list and set as Array
        while(st2.hasMoreTokens()) {
        	relatedToTopicList.add(st2.nextToken().trim());
        }
    
    }
 
    public List<String> getRelatedProductList(String query) {
            	
    	String country = null;
        query = query.toLowerCase();
        List<String> matched = new ArrayList<String>();
        for(int i=0; i < relatedProduct.size(); i++) {
            country = relatedProduct.get(i).toLowerCase();
            if(country.startsWith(query)) {
                matched.add(relatedProduct.get(i));
            }
        }
        return matched;
    }

    public List<String> getRelatedToTopicList(String query) {
        String relatedToTopic = null;
        query = query.toLowerCase();
        List<String> matched = new ArrayList<String>();
        for(int i=0; i < relatedToTopicList.size(); i++) {
        	relatedToTopic = relatedToTopicList.get(i).toLowerCase();
            if(relatedToTopic.startsWith(query)) {
                matched.add(relatedToTopicList.get(i));
            }
        }
        return matched;
    }
}